package com.eight.student.service.impl;

import com.eight.common.pojo.TbMember;
import com.eight.student.mapper.MemberMapper;
import com.eight.student.service.MemberService;
import com.eight.student.vo.MemberVo;
import com.eight.student.vo.MemberVo2;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @program: educaion-parent
 * @description:
 * @author: 平家祥
 * @create: 2023-05-26 15:48
 **/
@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    MemberMapper mapper;


    /**
     *  分页查询
     */
    @Override
    public Page<TbMember> findAll(Integer current, Integer pageSize, MemberVo strudentVo) {

        Page<TbMember> page = new Page<>(current,pageSize);
        QueryWrapper<TbMember> wrapper = new QueryWrapper<>();

        if(StringUtils.hasText(strudentVo.getMobile())){
            wrapper.eq("mobile",strudentVo.getMobile());
        }
        if(StringUtils.hasText(strudentVo.getNickname())){
            wrapper.like("nickname",strudentVo.getNickname());
        }
        if(strudentVo.getIsDisabled()!=null){
            wrapper.eq("is_disabled",strudentVo.getIsDisabled());
        }
        if(strudentVo.getGmtCreate()!=null&&strudentVo.getGmtCreate().size()>=2){
            wrapper.between("gmt_create",strudentVo.getGmtCreate().get(0),strudentVo.getGmtCreate().get(1));
        }
        Page<TbMember> page1 = mapper.selectPage(page,wrapper);
        return page1;
    }
    /**
     *   post stateChange   状态发生改边
     */
    @Override
    public Integer UpdateById( Integer isDisabled, String id) {
        TbMember tbMember = new TbMember();
        tbMember.setIsDisabled(isDisabled);
        tbMember.setId(id);
        tbMember.setGmtModified(LocalDateTime.now());
        return mapper.updateById(tbMember);

    }

    /**
     * 修改数据
     */
    @Override
    public Integer update(MemberVo2 memberVo2) {
        return mapper.update1(memberVo2);
    }


}
